package com.unieagle.exam.ui;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

import com.igexin.sdk.PushManager;
import com.unieagle.exam.R;
import com.unieagle.exam.account.AccountManager;
import com.unieagle.exam.service.ExamIntentService;
import com.unieagle.exam.service.ExamPushService;

public class SplashActivity extends BaseActivity
{

	private final int TIME_SPLASH = 2000;

    private Handler mHandler = new Handler();
    
	@Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash_layout);
        PushManager.getInstance().initialize(this.getApplicationContext(), ExamPushService.class);
        PushManager.getInstance().registerPushIntentService(this.getApplicationContext(), ExamIntentService.class);
        mHandler.postDelayed(new Runnable()
        {
            @Override
            public void run()
            {
                enterApp();
            }
        }, TIME_SPLASH);
    }
	
    private void enterApp()
    {
    	Intent intent;
    	if(AccountManager.getInstance().isLogin()) { 
    		if(AccountManager.getInstance().getUserInfo().getActivation_status().equals("activation_active")) {
    			intent = new Intent(SplashActivity.this, AddSubjectActivity.class);
    			intent.putExtra("from_splash", true);
    		} else {
    			intent = new Intent(SplashActivity.this, SubjectChooseActivity.class);
    		}
    	} else {
    		intent = new Intent(SplashActivity.this, LoginActivity.class);
    	}
        startActivity(intent);
        finish();
    }

}
